const { ResponseMessage } = require('@/utils/response/response_message');

class ResponseBody {
  /**
   * @param {number} code 响应码
   * @param {boolean} success 成功
   * @param {string} message 响应信息
   * @param {any} data 数据
   */
  constructor(code, success, message, data) {
    this.code = code;
    this.success = success;
    this.message = message;
    this.data = data;
  }

  /**
   * @param {any} data 数据
   * @returns {ResponseBody} 响应体
   */
  static success(data) {
    return new ResponseBody(ResponseMessage.SUCCESS.code, true, ResponseMessage.SUCCESS.message, data);
  }

  /**
   * @param {Object} err 错误
   * @param {any} data 数据
   * @returns {ResponseBody} 响应体
   */
  static error(err, data) {
    return new ResponseBody(err.code, false, err.message, data);
  }
}
exports.ResponseBody = ResponseBody;
